﻿using XinLife.Common.Filters;
using XinLife.Core;
using XinLife.Core.Extention;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using System.Text;
using Microsoft.AspNetCore.SignalR;
using XinLife.Common.SignalR;

namespace XinLife.Controllers
{
    public class HomeController : BaseController
    {
        private readonly IHttpClientFactory _httpClientFactory;
        private readonly ILogger<HomeController> _logger;//日志
        private readonly IHubContext<ChatHub, IChatClient> _hubContext;
        public HomeController(ILogger<HomeController> logger, IHttpClientFactory httpClientFactory, IHubContext<ChatHub, IChatClient> hubContext)
        {
            _logger = logger;
            _hubContext= hubContext;
            _httpClientFactory = httpClientFactory;
        }

        [HttpGet]
        public async Task<object> Index()
        {
            await _hubContext.Clients.All.SetOnlineNumber(100);
            //var a = await _freeSql.Queryable<Clinic>().ToListAsync();

            //var sql = _freeSql.Select<Clinic>()
            //                  .AsTable((type, oldname) => "table_1")
            //                  .ToSql(a => a.cId);
            //var httpClient = _httpClientFactory.CreateClient("HttpMessageHandler");
            //using (HttpContent content1 = new StringContent(new { a = 1 }.ToJson(), Encoding.UTF8, "application/json"))
            //{
            //    var responseMessage = await httpClient.PostAsync("http://localhost:5258/api/Login/LoginOut", new StringContent(""));
            //    return responseMessage.Content.ReadAsStringAsync();
            //}
            return "";
        }
    }
}
